# encoding:utf-8
from kafka import KafkaProducer
import json
import time
# 模拟opc启停
topic = "opc_data"
producer = KafkaProducer(bootstrap_servers=["10.90.15.107:9092"])

for i in range(15000):
    ctime = int(round(time.time() * 1000))
    loadInfo = {
        "type": "opc",
        "serverName": "水泥磨电机8--启停",
        "ipAddress": "1.1.1.1:244",
        "identifier": "group_qt2.item_qt2",
        "dataType": "UInt16",
        "value": "0",  # 0开机，1关机
        "collectTime": f"{ctime}"
    }
    data = json.dumps(loadInfo, ensure_ascii=True).encode("utf-8")
    print(f'第{i}次:, {data}')
    producer.send(topic, data)
    time.sleep(1)
producer.close()


